.class public final Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;
.super Ljava/lang/Object;
.source "MemoryCookieStorage.java"

# interfaces
.implements Lcom/burstly/lib/network/beans/cookie/ICookieStorage;


# static fields
.field private static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final TAG:Ljava/lang/String; = "MemoryCookieStorage"


# instance fields
.field private final mCookies:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;",
            ">;"
        }
    .end annotation
.end field

.field private final mLock:Ljava/lang/Object;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 44
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    return-void
.end method

.method public constructor <init>(Ljava/util/Collection;)V
    .locals 6
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Collection",
            "<",
            "Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 62
    .local p1, initialCookies:Ljava/util/Collection;,"Ljava/util/Collection<Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;>;"
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 49
    new-instance v2, Ljava/lang/Object;

    invoke-direct {v2}, Ljava/lang/Object;-><init>()V

    iput-object v2, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mLock:Ljava/lang/Object;

    .line 54
    new-instance v2, Ljava/util/HashMap;

    const/16 v3, 0x42

    invoke-direct {v2, v3}, Ljava/util/HashMap;-><init>(I)V

    iput-object v2, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    .line 63
    if-eqz p1, :cond_1

    invoke-interface {p1}, Ljava/util/Collection;->isEmpty()Z

    move-result v2

    if-nez v2, :cond_1

    .line 64
    invoke-interface {p1}, Ljava/util/Collection;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i$:Ljava/util/Iterator;
    :cond_0
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_1

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;

    .line 65
    .local v0, cookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    if-eqz v0, :cond_0

    .line 66
    iget-object v2, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;->getCookie()Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    move-result-object v3

    invoke-virtual {v3}, Lcom/burstly/lib/network/beans/cookie/CookieHolder;->getName()Ljava/lang/String;

    move-result-object v3

    invoke-interface {v2, v3, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    goto :goto_0

    .line 70
    .end local v0           #cookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .end local v1           #i$:Ljava/util/Iterator;
    :cond_1
    sget-object v2, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "MemoryCookieStorage"

    const-string v4, "Initialization completed."

    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v2, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 71
    return-void
.end method

.method private deleteInvalidCookies()V
    .locals 12

    .prologue
    .line 89
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v1

    .line 90
    .local v1, currentTime:J
    const/4 v0, 0x0

    .line 92
    .local v0, cookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    iget-object v4, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-interface {v4}, Ljava/util/Map;->isEmpty()Z

    move-result v4

    if-nez v4, :cond_1

    .line 93
    iget-object v4, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-interface {v4}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v4

    invoke-interface {v4}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v3

    .line 94
    .local v3, iterator:Ljava/util/Iterator;,"Ljava/util/Iterator<Ljava/util/Map$Entry<Ljava/lang/String;Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;>;>;"
    :cond_0
    :goto_0
    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_1

    .line 95
    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/util/Map$Entry;

    invoke-interface {v4}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v0

    .end local v0           #cookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    check-cast v0, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;

    .line 96
    .restart local v0       #cookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;->getExpirationTime()J

    move-result-wide v4

    cmp-long v4, v4, v1

    if-gez v4, :cond_0

    .line 97
    sget-object v4, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v5, "MemoryCookieStorage"

    const-string v6, "Cookie expired: {0}. Expiration time: {1}"

    const/4 v7, 0x2

    new-array v7, v7, [Ljava/lang/Object;

    const/4 v8, 0x0

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;->getCookie()Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    move-result-object v9

    aput-object v9, v7, v8

    const/4 v8, 0x1

    new-instance v9, Ljava/util/Date;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;->getExpirationTime()J

    move-result-wide v10

    invoke-direct {v9, v10, v11}, Ljava/util/Date;-><init>(J)V

    aput-object v9, v7, v8

    invoke-virtual {v4, v5, v6, v7}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 99
    invoke-interface {v3}, Ljava/util/Iterator;->remove()V

    goto :goto_0

    .line 103
    .end local v3           #iterator:Ljava/util/Iterator;,"Ljava/util/Iterator<Ljava/util/Map$Entry<Ljava/lang/String;Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;>;>;"
    :cond_1
    return-void
.end method


# virtual methods
.method public clear()V
    .locals 2

    .prologue
    .line 150
    iget-object v1, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mLock:Ljava/lang/Object;

    monitor-enter v1

    .line 151
    :try_start_0
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-interface {v0}, Ljava/util/Map;->clear()V

    .line 152
    monitor-exit v1

    .line 153
    return-void

    .line 152
    :catchall_0
    move-exception v0

    monitor-exit v1
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public deleteCookie(Ljava/lang/String;)V
    .locals 2
    .parameter "cookieName"

    .prologue
    .line 139
    if-eqz p1, :cond_0

    .line 140
    iget-object v1, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mLock:Ljava/lang/Object;

    monitor-enter v1

    .line 141
    :try_start_0
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-interface {v0, p1}, Ljava/util/Map;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 142
    monitor-exit v1

    .line 144
    :cond_0
    return-void

    .line 142
    :catchall_0
    move-exception v0

    monitor-exit v1
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public getValidCookies()Ljava/util/Collection;
    .locals 3
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/Collection",
            "<",
            "Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;",
            ">;"
        }
    .end annotation

    .prologue
    .line 75
    iget-object v1, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mLock:Ljava/lang/Object;

    monitor-enter v1

    .line 76
    :try_start_0
    invoke-direct {p0}, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->deleteInvalidCookies()V

    .line 77
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-interface {v0}, Ljava/util/Map;->isEmpty()Z

    move-result v0

    if-nez v0, :cond_0

    .line 78
    new-instance v0, Ljava/util/ArrayList;

    iget-object v2, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-interface {v2}, Ljava/util/Map;->values()Ljava/util/Collection;

    move-result-object v2

    invoke-direct {v0, v2}, Ljava/util/ArrayList;-><init>(Ljava/util/Collection;)V

    monitor-exit v1

    .line 80
    :goto_0
    return-object v0

    :cond_0
    invoke-static {}, Ljava/util/Collections;->emptyList()Ljava/util/List;

    move-result-object v0

    monitor-exit v1

    goto :goto_0

    .line 81
    :catchall_0
    move-exception v0

    monitor-exit v1
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public processCookies(Ljava/util/Collection;)V
    .locals 15
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Collection",
            "<",
            "Lcom/burstly/lib/network/beans/cookie/CookieHolder;",
            ">;)V"
        }
    .end annotation

    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 107
    .local p1, inputCookies:Ljava/util/Collection;,"Ljava/util/Collection<Lcom/burstly/lib/network/beans/cookie/CookieHolder;>;"
    if-nez p1, :cond_0

    .line 108
    new-instance v6, Ljava/lang/IllegalArgumentException;

    const-string v7, "Cannot process null-referenced list of cookies."

    invoke-direct {v6, v7}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v6

    .line 110
    :cond_0
    invoke-interface/range {p1 .. p1}, Ljava/util/Collection;->isEmpty()Z

    move-result v6

    if-eqz v6, :cond_1

    .line 131
    :goto_0
    return-void

    .line 114
    :cond_1
    const/4 v3, 0x0

    .line 115
    .local v3, newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    const/4 v5, 0x0

    .line 116
    .local v5, prevCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    iget-object v7, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mLock:Ljava/lang/Object;

    monitor-enter v7

    .line 117
    :try_start_0
    invoke-interface/range {p1 .. p1}, Ljava/util/Collection;->iterator()Ljava/util/Iterator;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    move-result-object v2

    .local v2, i$:Ljava/util/Iterator;
    move-object v4, v3

    .end local v3           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .local v4, newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    :goto_1
    :try_start_1
    invoke-interface {v2}, Ljava/util/Iterator;->hasNext()Z

    move-result v6

    if-eqz v6, :cond_3

    invoke-interface {v2}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    .line 118
    .local v1, cookie:Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    if-eqz v1, :cond_4

    .line 119
    new-instance v3, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;

    invoke-direct {v3, v1}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;-><init>(Lcom/burstly/lib/network/beans/cookie/CookieHolder;)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1

    .line 120
    .end local v4           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .restart local v3       #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    :try_start_2
    iget-object v6, p0, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->mCookies:Ljava/util/Map;

    invoke-virtual {v1}, Lcom/burstly/lib/network/beans/cookie/CookieHolder;->getName()Ljava/lang/String;

    move-result-object v8

    invoke-interface {v6, v8, v3}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v6

    move-object v0, v6

    check-cast v0, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;

    move-object v5, v0

    .line 121
    if-eqz v5, :cond_2

    .line 122
    sget-object v6, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "MemoryCookieStorage"

    const-string v9, "Cookie updated: {0}. Expiration time: {1}"

    const/4 v10, 0x2

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    aput-object v1, v10, v11

    const/4 v11, 0x1

    new-instance v12, Ljava/util/Date;

    invoke-virtual {v3}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;->getExpirationTime()J

    move-result-wide v13

    invoke-direct {v12, v13, v14}, Ljava/util/Date;-><init>(J)V

    aput-object v12, v10, v11

    invoke-virtual {v6, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    :goto_2
    move-object v4, v3

    .line 125
    .end local v3           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .restart local v4       #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    goto :goto_1

    .end local v4           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .restart local v3       #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    :cond_2
    sget-object v6, Lcom/burstly/lib/network/beans/cookie/MemoryCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "MemoryCookieStorage"

    const-string v9, "New cookie added: {0}. Expiration time: {1}"

    const/4 v10, 0x2

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    aput-object v1, v10, v11

    const/4 v11, 0x1

    new-instance v12, Ljava/util/Date;

    invoke-virtual {v3}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;->getExpirationTime()J

    move-result-wide v13

    invoke-direct {v12, v13, v14}, Ljava/util/Date;-><init>(J)V

    aput-object v12, v10, v11

    invoke-virtual {v6, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_2

    .line 130
    .end local v1           #cookie:Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    .end local v2           #i$:Ljava/util/Iterator;
    :catchall_0
    move-exception v6

    :goto_3
    monitor-exit v7
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    throw v6

    .end local v3           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .restart local v2       #i$:Ljava/util/Iterator;
    .restart local v4       #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    :cond_3
    :try_start_3
    monitor-exit v7
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_1

    goto :goto_0

    :catchall_1
    move-exception v6

    move-object v3, v4

    .end local v4           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .restart local v3       #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    goto :goto_3

    .end local v3           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .restart local v1       #cookie:Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    .restart local v4       #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    :cond_4
    move-object v3, v4

    .end local v4           #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .restart local v3       #newCookieWrp:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    goto :goto_2
.end method
